<?php

/**
 * Created by PhpStorm.
 * User: Bruce
 * Date: 2020/5/28
 * Time: 16:14
 */
class Listt
{
    public $current;
    public $next;

    public function __construct($current, $next)
    {
        $this->current = $current;
        $this->next = $next;
    }
}

function intersection($headA, $headB)
{
    $a = $headA;
    $b = $headB;

    while($a != $b){
        if($a){
            $a = $a->next;
        }else{
            $a = $headB;
        }

        if($b){
            $b = $b->next;
        }else{
            $b = $headA;
        }
    }
    return $a;
}


$headA = new Listt(1, new Listt(2, new Listt(3, new Listt(4, null))));
$headB = new Listt(11, new Listt(22, new Listt(33, new Listt(45, null))));
var_dump(intersection($headA, $headB));
